# -*- coding:utf-8 -*-
from . import db

def addContact(name, company, phone, email):
    return db.insert('contact', name = name, company = company, phone = phone, email = email)

def getById(contactId):
    result = db.query('SELECT * FROM contact WHERE id = $contactId', locals())
    if result:
        return result[0]
    return None

def getAllContacts():
    result = db.query('SELECT * FROM contact')
    return list(result)

def deleteById(contactId):
    return db.delete('contact', 'id = $contactId', vars = locals())

def clear():
    db.query('delete from contact')
